using System;
using System.Data;
using System.Collections;
using System.Runtime.Serialization;
using Widgetsphere.Core.Util;
using Widgetsphere.Core.DataAccess;
using System.Collections.Generic;
using ACME.Northwind.Business.Objects;
using ACME.Northwind.Domain.Objects;

namespace ACME.Northwind.Business.SelectCommands
{
	#region ProductSelectAll

	/// <summary>
	/// The select command used to select all rows from the 'Product' table
	/// </summary>
	[Serializable]
	public partial class ProductSelectAll : SelectCommand, ISerializable
	{

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected ProductSelectAll(SerializationInfo info, StreamingContext context): base(info,context)
		{
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
		}

		#endregion 

		/// <summary>
		/// Default constructor
		/// </summary>
		public ProductSelectAll()
		{
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainProductCollection colDomain = new DomainProductCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values to populate a 'Product' collection
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "gen_ProductSelect"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region ProductPagedSelect

	/// <summary>
	/// Select command used to perform paged selects from the 'Product' table
	/// </summary>
	[Serializable]
	public partial class ProductPagedSelect : SelectCommand, ISerializable
	{
		private int mPage; 
		private int mPageSize;
		private string mOrderByColumn;
		private bool mAscending;
		private string mFilter;
		private int mCount = -1;

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected ProductPagedSelect(SerializationInfo info, StreamingContext context): base(info,context)
		{
			mPage = info.GetInt32("mPage");
			mPageSize = info.GetInt32("mPageSize");
			mOrderByColumn = info.GetString("mOrderByColumn");
			mAscending = info.GetBoolean("mAscending");
			mFilter = info.GetString("mFilter");
			mCount = info.GetInt32("mCount");
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("mPage", mPage);
			info.AddValue("mPageSize", mPageSize);
			info.AddValue("mOrderByColumn", mOrderByColumn);
			info.AddValue("mAscending", mAscending);
			info.AddValue("mFilter", mFilter);
			info.AddValue("mCount", mCount);
		}

		#endregion 

		/// <summary>
		/// Paging select command that allows for the selective page-based selection of database rows
		/// </summary>
		public ProductPagedSelect(int page, int pageSize, string orderByColumn, bool ascending, string filter)
		{
			mPage = page; 
			mPageSize = pageSize;
			mOrderByColumn = orderByColumn;
			mAscending = ascending;
			mFilter = filter;
		}

		/// <summary>
		/// The total number of rows returned. This is populated after the database is queried.
		/// </summary>
		public int Count
		{
		  get { return mCount; }
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainProductCollection colDomain = new DomainProductCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values to populate a 'Product' collection in a paged fashion
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "gen_ProductPagingSelect"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
		}

		/// <summary>
		/// Execute this select command on the database
		/// </summary>
		public override IDomainCollection Execute(SubDomainBase subDomain)
		{
			this.SetupParameterValues(subDomain);
			PersistableDomainCollectionBase returnTable = (PersistableDomainCollectionBase)this.CreateDomainCollection();

			IDbCommand fillCommand = PersistableDomainCollectionBase.GetFillCommand(this.ConnectionString, this.StoredProcedureName);
			fillCommand.CommandTimeout = this.DefaultTimeOut;
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@page", mPage);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@pageSize", mPageSize);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@orderByColumn", mOrderByColumn);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@ascending", mAscending);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@filter", mFilter);
			IDbDataParameter paramCount = PersistableDomainCollectionBase.GetOutputParameter(fillCommand, "@count");
			returnTable.FillDataTable(this.ConnectionString, fillCommand);
			if(paramCount.Value != System.DBNull.Value)
			{
				mCount = (int)paramCount.Value;
			}
			else
			{
				mCount = 0;
			}
			return returnTable;
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region ProductSelectByPks

	/// <summary>
	/// A select command that selects objects by primary key
	/// </summary>
	[Serializable]
	public partial class ProductSelectByPks : SelectCommand, ISerializable
	{
		private List<ProductPrimaryKey> mPrimaryKeys = null;

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected ProductSelectByPks(SerializationInfo info, StreamingContext context): base(info,context)
		{
			mPrimaryKeys = new List<ProductPrimaryKey>();
			mPrimaryKeys.AddRange((ProductPrimaryKey[])info.GetValue("mPrimaryKeys", typeof(ProductPrimaryKey[])));
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("mPrimaryKeys", mPrimaryKeys.ToArray());
		}

		#endregion 

		/// <summary>
		/// Select objects by primary key
		/// </summary>
		public ProductSelectByPks(int productid)
		{
			mPrimaryKeys = new List<ProductPrimaryKey>();
			mPrimaryKeys.Add(new ProductPrimaryKey(productid));

		}

		/// <summary>
		/// Select objects by a primary key
		/// </summary>
		public ProductSelectByPks(ProductPrimaryKey primaryKey)
		{
			mPrimaryKeys = new List<ProductPrimaryKey>();
			mPrimaryKeys.Add(primaryKey);
		}

		/// <summary>
		/// Select objects by a list of primary keys
		/// </summary>
		public ProductSelectByPks(IEnumerable<ProductPrimaryKey> primaryKeys)
		{
			mPrimaryKeys = new List<ProductPrimaryKey>();
			mPrimaryKeys.AddRange(primaryKeys);
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainProductCollection colDomain = new DomainProductCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values by primary key to populate a 'Product' collection
		/// </summary>
		public override string StoredProcedureName
		{
			get
			{
				if (mPrimaryKeys.Count == 1) return "gen_ProductSelectByProductSinglePk";
				else return "gen_ProductSelectByProductPks";
			}
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			if (mPrimaryKeys.Count == 1)
			{
				ProductPrimaryKey key = ((ProductPrimaryKey)mPrimaryKeys[0]);
				ParameterValues.Add("@ProductID", key.ProductId);
			}
			else
				ParameterValues.Add("@xml", DomainProductCollection.GetPrimaryKeyXml(mPrimaryKeys));
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region ProductSelectByCategoryPks

	/// <summary>
	/// Select command used to select all rows from the 'Product' table based on primary keys
	/// </summary>
	[Serializable]
	public partial class ProductSelectByCategoryPks : SelectCommand, ISerializable
	{
		private string mCategoryPrimaryKeysXml = null;

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected ProductSelectByCategoryPks(SerializationInfo info, StreamingContext context): base(info,context)
		{
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
		}

		#endregion 

		/// <summary>
		/// Default constructor
		/// </summary>
		public ProductSelectByCategoryPks()
		{
		}

		/// <summary>
		/// Constructor that takes a list of primary keys to select
		/// </summary>
		public ProductSelectByCategoryPks(IEnumerable<CategoryPrimaryKey> inCategoryPrimaryKeys)
		{
			mCategoryPrimaryKeysXml = DomainCategoryCollection.GetPrimaryKeyXml(inCategoryPrimaryKeys);
		}

		/// <summary>
		/// Creates a PersistableDomainCollectionBase of a collection type that holds objects selected by this select command
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainProductCollection colDomain = new DomainProductCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values by a foreign key to populate a 'Product' collection
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "gen_ProductSelectByCategoryPks"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			SubDomain sd = (SubDomain)subDomain;
			if(mCategoryPrimaryKeysXml != null)
			{
				if (!ParameterValues.ContainsKey("@xml"))
					ParameterValues.Add("@xml", mCategoryPrimaryKeysXml);
			}
			else
			{
				DomainCategoryCollection ic = (DomainCategoryCollection)sd.GetDomainCollection(Collections.CategoryCollection);
				ic.ProductFilled = true;
				if (!ParameterValues.ContainsKey("@xml"))
					ParameterValues.Add("@xml", ic.GetPrimaryKeyXml());
			}
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region ProductSelectBySupplierPks

	/// <summary>
	/// Select command used to select all rows from the 'Product' table based on primary keys
	/// </summary>
	[Serializable]
	public partial class ProductSelectBySupplierPks : SelectCommand, ISerializable
	{
		private string mSupplierPrimaryKeysXml = null;

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected ProductSelectBySupplierPks(SerializationInfo info, StreamingContext context): base(info,context)
		{
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
		}

		#endregion 

		/// <summary>
		/// Default constructor
		/// </summary>
		public ProductSelectBySupplierPks()
		{
		}

		/// <summary>
		/// Constructor that takes a list of primary keys to select
		/// </summary>
		public ProductSelectBySupplierPks(IEnumerable<SupplierPrimaryKey> inSupplierPrimaryKeys)
		{
			mSupplierPrimaryKeysXml = DomainSupplierCollection.GetPrimaryKeyXml(inSupplierPrimaryKeys);
		}

		/// <summary>
		/// Creates a PersistableDomainCollectionBase of a collection type that holds objects selected by this select command
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainProductCollection colDomain = new DomainProductCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values by a foreign key to populate a 'Product' collection
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "gen_ProductSelectBySupplierPks"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			SubDomain sd = (SubDomain)subDomain;
			if(mSupplierPrimaryKeysXml != null)
			{
				if (!ParameterValues.ContainsKey("@xml"))
					ParameterValues.Add("@xml", mSupplierPrimaryKeysXml);
			}
			else
			{
				DomainSupplierCollection ic = (DomainSupplierCollection)sd.GetDomainCollection(Collections.SupplierCollection);
				ic.ProductFilled = true;
				if (!ParameterValues.ContainsKey("@xml"))
					ParameterValues.Add("@xml", ic.GetPrimaryKeyXml());
			}
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region ProductSelectByCreatedDateRange

	/// <summary>
	/// Select objects by their created date.
	/// </summary>
	[Serializable]
	public partial class ProductSelectByCreatedDateRange : SelectCommand, ISerializable
	{
		private DateTime? mStartDate;
		private DateTime? mEndDate;

		#region Serialization

		/// <summary>
		/// Select objects by their created date.
		/// </summary>
		protected ProductSelectByCreatedDateRange(SerializationInfo info, StreamingContext context): base(info,context)
		{
			mStartDate = info.GetDateTime("mStartDate");
			mEndDate = info.GetDateTime("mEndDate");
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("mStartDate", mStartDate);
			info.AddValue("mEndDate", mEndDate);
		}

		#endregion 

		/// <summary>
		/// Select objects by their created date.
		/// </summary>
		public ProductSelectByCreatedDateRange(DateTime? startDate, DateTime? endDate)
		{
			mStartDate = startDate;
			mEndDate = endDate;
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainProductCollection colDomain = new DomainProductCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values to populate a 'Product' collection in a paged fashion
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "gen_ProductSelectByCreatedDateRange"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			ParameterValues.Add("@start_date", mStartDate);
			ParameterValues.Add("@end_date", mEndDate);
		}

		/// <summary>
		/// Execute this select command on the database
		/// </summary>
		public override IDomainCollection Execute(SubDomainBase subDomain)
		{
			this.SetupParameterValues(subDomain);
			PersistableDomainCollectionBase returnTable = (PersistableDomainCollectionBase)this.CreateDomainCollection();

			IDbCommand fillCommand = PersistableDomainCollectionBase.GetFillCommand(this.ConnectionString, this.StoredProcedureName);
			fillCommand.CommandTimeout = this.DefaultTimeOut;
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@start_date", mStartDate);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@end_date", mEndDate);
			returnTable.FillDataTable(this.ConnectionString, fillCommand);
			return returnTable;
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region ProductSelectByModifiedDateRange

	/// <summary>
	/// Select objects by their modified date.
	/// </summary>
	[Serializable]
	public partial class ProductSelectByModifiedDateRange : SelectCommand, ISerializable
	{
		private DateTime? mStartDate;
		private DateTime? mEndDate;

		#region Serialization

		/// <summary>
		/// Select objects by their modified date.
		/// </summary>
		protected ProductSelectByModifiedDateRange(SerializationInfo info, StreamingContext context): base(info,context)
		{
			mStartDate = info.GetDateTime("mStartDate");
			mEndDate = info.GetDateTime("mEndDate");
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("mStartDate", mStartDate);
			info.AddValue("mEndDate", mEndDate);
		}

		#endregion 

		/// <summary>
		/// Select objects by their modified date.
		/// </summary>
		public ProductSelectByModifiedDateRange(DateTime? startDate, DateTime? endDate)
		{
			mStartDate = startDate;
			mEndDate = endDate;
		}

		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainProductCollection colDomain = new DomainProductCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values to populate a 'Product' collection in a paged fashion
		/// </summary>
		public override string StoredProcedureName
		{
			get { return "gen_ProductSelectByModifiedDateRange"; }
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			ParameterValues.Add("@start_date", mStartDate);
			ParameterValues.Add("@end_date", mEndDate);
		}

		/// <summary>
		/// Execute this select command on the database
		/// </summary>
		public override IDomainCollection Execute(SubDomainBase subDomain)
		{
			this.SetupParameterValues(subDomain);
			PersistableDomainCollectionBase returnTable = (PersistableDomainCollectionBase)this.CreateDomainCollection();

			IDbCommand fillCommand = PersistableDomainCollectionBase.GetFillCommand(this.ConnectionString, this.StoredProcedureName);
			fillCommand.CommandTimeout = this.DefaultTimeOut;
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@start_date", mStartDate);
			PersistableDomainCollectionBase.SetParameterValue(fillCommand, "@end_date", mEndDate);
			returnTable.FillDataTable(this.ConnectionString, fillCommand);
			return returnTable;
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion

	}

	#endregion

	#region ProductSelectBySearch
	/// <summary>
	/// The select command used to select all rows from the 'Product' table
	/// </summary>
	[Serializable]
	public partial class ProductSelectBySearch : SelectCommand, ISerializable
	{
		private ProductSearch Product;
		private ProductPaging _paging = null;
		private int mCount = -1;

		#region Serialization

		/// <summary>
		/// Serialization constructor
		/// </summary>
		protected ProductSelectBySearch(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
			Product = (ProductSearch)info.GetValue("Product", typeof(ProductSearch));
			_paging = (ProductPaging)info.GetValue("paging", typeof(ProductPaging));
		}

		/// <summary>
		/// Method used internally for serialization
		/// </summary>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("Product", Product);
			info.AddValue("paging", _paging);
		}

		#endregion 

		/// <summary>
		/// The total number of rows returned. This is populated after the database is queried.
		/// </summary>
		public int Count
		{
		  get { return mCount; }
		}

		/// <summary>
		/// Select of objects by the Product search object
		/// </summary>
		public ProductSelectBySearch(ProductSearch searchObject)
		{
			Product = searchObject;
		}

		/// <summary>
		/// Paged select of objects by the Product search object
		/// </summary>
		public ProductSelectBySearch(ProductSearch searchObject, ProductPaging paging)
		{
			Product = searchObject;
			_paging = paging;
		}


		/// <summary>
		/// Creates a persistable domainCollection
		/// </summary>
		public override IDomainCollection CreateDomainCollection()
		{
			DomainProductCollection colDomain = new DomainProductCollection();
			return colDomain;
		}

		/// <summary>
		/// The stored procedure name to select values by primary key to populate a 'Product' collection
		/// </summary>
		public override string StoredProcedureName
		{
			get
			{
				if (Product.SearchType == SearchType.OR)
					return "gen_ProductSelectBySearchOr";
				else
					return "gen_ProductSelectBySearchAnd";
			}
		}

		/// <summary>
		/// Initializes the parameters for this select command
		/// </summary>
		protected override void SetupParameterValues(SubDomainBase subDomain)
		{
			if (_paging != null)
			{
				if (_paging.OrderByList.Count != 1)
					throw new Exception("The select operation supports exactly one OrderBy field.");

				ParameterValues.Add("@paging_Ascending", _paging.OrderByList[0].Ascending);
				ParameterValues.Add("@paging_OrderByColumn", ProductCollection.GetDatabaseFieldName(_paging.OrderByList[0].Field));
				ParameterValues.Add("@paging_PageIndex", _paging.PageIndex);
				ParameterValues.Add("@paging_RecordsperPage", _paging.RecordsperPage);
			}

			if (Product != null)
			{
				if (Product.CategoryId != null)
				{
					ParameterValues.Add("@CategoryID", Product.CategoryId);
				}
				if (Product.Discontinued != null)
				{
					ParameterValues.Add("@Discontinued", Product.Discontinued);
				}
				if (Product.ProductId != null)
				{
					ParameterValues.Add("@ProductID", Product.ProductId);
				}
				if (Product.ProductName != null)
				{
					ParameterValues.Add("@ProductName", Product.ProductName);
				}
				if (Product.QuantityPerUnit != null)
				{
					ParameterValues.Add("@QuantityPerUnit", Product.QuantityPerUnit);
				}
				if (Product.ReorderLevel != null)
				{
					ParameterValues.Add("@ReorderLevel", Product.ReorderLevel);
				}
				if (Product.SupplierId != null)
				{
					ParameterValues.Add("@SupplierID", Product.SupplierId);
				}
				if (Product.UnitsInStock != null)
				{
					ParameterValues.Add("@UnitsInStock", Product.UnitsInStock);
				}
				if (Product.UnitsOnOrder != null)
				{
					ParameterValues.Add("@UnitsOnOrder", Product.UnitsOnOrder);
				}

			}
		}

		/// <summary>
		/// Execute this select command on the database
		/// </summary>
		public override IDomainCollection Execute(SubDomainBase subDomain)
		{
			this.SetupParameterValues(subDomain);
			PersistableDomainCollectionBase returnTable = (PersistableDomainCollectionBase)this.CreateDomainCollection();

			IDbCommand fillCommand = PersistableDomainCollectionBase.GetFillCommand(this.ConnectionString, this.StoredProcedureName);
			fillCommand.CommandTimeout = this.DefaultTimeOut;

			//Add the parameters
			foreach (string key in ParameterValues.Keys)
			{
				PersistableDomainCollectionBase.SetParameterValue(fillCommand, key, ParameterValues[key]);
			}

			IDbDataParameter paramCount = null;
			paramCount = PersistableDomainCollectionBase.GetOutputParameter(fillCommand, "@paging_Count");

			returnTable.FillDataTable(this.ConnectionString, fillCommand);

			if (_paging != null)
			{
				if (paramCount.Value != System.DBNull.Value) mCount = (int)paramCount.Value;
				else mCount = 0;
			}

			return returnTable;
		}

		#region SelectCommand Abstact Override

		/// <summary>
		/// The connection string used to connect to the database
		/// </summary>
		public override string ConnectionString
		{
			get { return ConfigurationValues.GetInstance().ConnectionString; }
		}

		/// <summary>
		/// Determines the default time out
		/// </summary>
		public override int DefaultTimeOut
		{
			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }
		}

		#endregion


	}

	#endregion
}
